<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <!-- 让父组件的变量和子组件里面input框的内容做数据的双向绑定 -->
      <h2>组件添加v-model</h2>
      <p>textValue: {{textValue}}</p>
      <child :value="textValue" @value-change="valueChange"></child>
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      const { createApp } = Vue;
      const Child = {
        props: {
          value: String,
        },
        emits: ["valueChange"],
        template: `
          <div>
            <div>这是child子组件</div>
            <input type="text" :value="value" @input="handleChange" />
          </div>
        `,
        methods: {
          handleChange(e) {
            // console.log(e.target.value);
            this.$emit("valueChange", e.target.value);
          },
        },
      };

      const app = createApp({
        data() {
          return {
            textValue: "abc",
          };
        },
        methods: {
          valueChange(v) {
            this.textValue = v;
          },
        },
        components: {
          Child,
        },
      });

      app.mount("#app");
    </script>
  </body>
</html>
